﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

namespace Election
{
    public partial class Main_login : Form
    {
        public static bool loggedin = false;

		private void Form_Login_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (loggedin == false)
				Application.Exit();
		}

        public Main_login()
        {
            InitializeComponent();
			this.FormClosing += new FormClosingEventHandler(Form_Login_FormClosing);
        }

        private void DangNhapbutton_Click(object sender, EventArgs e)
        {

            orcl.conn = new OracleConnection();
            

            orcl.conn.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));User Id=" +
                 this.userNametextBox.Text + ";Password=" +
                 this.PasswordtextBox.Text + ";";
            if (this.userNametextBox.Text.ToUpper() == "SYS")
                orcl.conn.ConnectionString += "DBA Privilege=SYSDBA;";

            try
            {
                orcl.conn.Open();
                if (orcl.conn.State.ToString() == "Open")
                {
                    orcl.user = this.userNametextBox.Text.ToUpper();
                    orcl.pass = this.PasswordtextBox.Text.ToUpper();
                    loggedin = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("kết nối thất bại", "info", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    orcl.conn.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
